package com.tt.fashionWebSite.util;

/**
 * Created by isoft-work 5 on 12/24/2014.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class ExchangeRate {

   private double getRate(String from, String to) {
      try {
         URL url = new URL("http://quote.yahoo.com/d/quotes.csv?f=l1&s=" + from + to + "=X");
         BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
         String line = reader.readLine();
         if (line.length() > 0) {
            return Double.parseDouble(line);
         }
         reader.close();
      } catch (IOException e) {
         System.out.println(e.getMessage());
      }

      return 0;
   }

   public double getVndUsdRate() {
      return getRate("USD", "VND");
   }

   public double getGoldEuroRate() {
      return getRate("XAU", "EUR");
   }

   public double getSilverEuroRate() {
      return getRate("XAG", "EUR");
   }
}

